<html>
<head><meta charset="utf-8"><title>no C unwind? · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html">no C unwind?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178780098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178780098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178780098">(Oct 22 2019 at 18:00)</a>:</h4>
<p>Based on discussion with <span class="user-mention" data-user-id="143274">@Amanieu</span> , I am hesitant to introduce any RFC with <code>extern "C unwind"</code>.</p>



<a name="178801296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801296">(Oct 22 2019 at 21:33)</a>:</h4>
<p>Say a bit more?</p>



<a name="178801447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801447">(Oct 22 2019 at 21:35)</a>:</h4>
<p>this sounds very surprising to me :)</p>



<a name="178801555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801555">(Oct 22 2019 at 21:37)</a>:</h4>
<p>I am surprised to be saying it!</p>



<a name="178801575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801575">(Oct 22 2019 at 21:37)</a>:</h4>
<p>So, Amanieu opened the new topic 'Allow unwinding from extern "C" by default', based on their PR to the compiler</p>



<a name="178801647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801647">(Oct 22 2019 at 21:38)</a>:</h4>
<p>I'm breaking this out into its own topic, but I'd definitely like to see some links to what is making you feel this way. I was hoping we could open up <em>some</em> kind of RFC this week :)</p>



<a name="178801661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801661">(Oct 22 2019 at 21:38)</a>:</h4>
<p>The suggestion is essentially like treating <code>extern "C"</code> the way we were planning to treat <code>extern "C unwind"</code></p>



<a name="178801703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801703">(Oct 22 2019 at 21:39)</a>:</h4>
<p>I brought up the various UB issues we were concerned about, and it sounds very possible that the possible UB from the LLVM perspective is actually quite minimal.</p>



<a name="178801805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801805">(Oct 22 2019 at 21:40)</a>:</h4>
<p>And, more generically, the possibility that LLVM can generate well-behaved code would, I think, mean that any other Rust implementation could, too</p>



<a name="178801821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801821">(Oct 22 2019 at 21:40)</a>:</h4>
<p>Hmm</p>



<a name="178801836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801836">(Oct 22 2019 at 21:41)</a>:</h4>
<p>Well, the main concern would I think be dead-code elim (or lack thereof)</p>



<a name="178801847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801847">(Oct 22 2019 at 21:41)</a>:</h4>
<p>"C unwind" is to some extent more of an <em>optimization</em></p>



<a name="178801853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801853">(Oct 22 2019 at 21:41)</a>:</h4>
<p>If I star comments here in Zulip, is that globally visible? I.e. could I quickly go into that thread and star various comments for you to read?</p>



<a name="178801855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801855">(Oct 22 2019 at 21:41)</a>:</h4>
<p>But this sounds like a great thing to try and create a "decision document" around</p>



<a name="178801858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801858">(Oct 22 2019 at 21:41)</a>:</h4>
<blockquote>
<p>If I star comments here in Zulip, is that globally visible? I.e. could I quickly go into that thread and star various comments for you to read?</p>
</blockquote>
<p>no</p>



<a name="178801867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801867">(Oct 22 2019 at 21:41)</a>:</h4>
<p>I can skim through that thread</p>



<a name="178801882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801882">(Oct 22 2019 at 21:41)</a>:</h4>
<p>Okay. Despite my previous comment, I think that would be worthwhile :)</p>



<a name="178801942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801942">(Oct 22 2019 at 21:42)</a>:</h4>
<p>And, much to my surprise, as far as I can tell, gnzlbg seems to agree w/ Amanieu's suggestion</p>



<a name="178801991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178801991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178801991">(Oct 22 2019 at 21:43)</a>:</h4>
<p>(surprise b/c I had been under the impression that treating <code>extern "C"</code> that way was not something gnzlbg was at all favorably disposed toward)</p>



<a name="178802013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802013">(Oct 22 2019 at 21:43)</a>:</h4>
<p>One person, I think, who may be able to read the thread and quickly point out issues with the proposal that I'm not seeing, would be Centril</p>



<a name="178802060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802060">(Oct 22 2019 at 21:44)</a>:</h4>
<p>so far from my skimming, there are a lot of details and my eyes are glazing over :P</p>



<a name="178802086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802086">(Oct 22 2019 at 21:44)</a>:</h4>
<p>(specifically it seems like, in the part I'm reading, there is some debate about whether it is or is not UB and under what circumstances)</p>



<a name="178802087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802087">(Oct 22 2019 at 21:44)</a>:</h4>
<p>I'm presuming this gets settled, let me see if I can find the spot</p>



<a name="178802088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802088">(Oct 22 2019 at 21:44)</a>:</h4>
<p>right....</p>



<a name="178802094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802094">(Oct 22 2019 at 21:45)</a>:</h4>
<p>but if we were to try and summarize, that would be an important thing to clarify</p>



<a name="178802168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802168">(Oct 22 2019 at 21:46)</a>:</h4>
<p>my understanding is that "we" (not sure if that would be anyone, or someone on the Rust team with an existing relationship) should reach out to LLVM somehow and ask for an explicit statement to the effect that unwinding across stack frames without landing pads is well defined unless those frames have destructors/RAII/<code>finally</code></p>



<a name="178802502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802502">(Oct 22 2019 at 21:52)</a>:</h4>
<p>I guess the key question is <em>why</em> we were saying that <code>extern "C"</code> functions should not allow unwinding by default. I'm not sure how well argued this point is. There are presumably a few possible aspects:</p>
<ul>
<li>Most C functions do not, in fact, unwind, so it's a reasonable "default".</li>
<li>Something something UB &lt;-- this seems to be what a lot of the thread is about, and in particular interactions around longjmp, but I found that a bit confusing.</li>
<li>It permits dead-code elimination.</li>
</ul>



<a name="178802509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802509">(Oct 22 2019 at 21:52)</a>:</h4>
<p>I'm a bit surprised to see discussion of <code>#[no_unwind]</code> attributes and not an ABI</p>



<a name="178802515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802515">(Oct 22 2019 at 21:52)</a>:</h4>
<p>Since the same arguments that led us to <code>"C unwind"</code> seem to apply in reverse</p>



<a name="178802958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178802958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178802958">(Oct 22 2019 at 21:58)</a>:</h4>
<p>The main discussions I remember about not unwinding through <code>extern "C"</code> were several months before I opened RFC 2699, so...quite long ago, and scattered across multiple GitHub and Discourse threads.</p>



<a name="178803123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803123">(Oct 22 2019 at 22:01)</a>:</h4>
<p>My memory is that there was concern that the behavior would be LLVM-undefined in many or most cases. (Arguably even all cases.) Certainly I was given the impression that when an unwind crosses a stack frame with no landing pads, the platform-level behavior is undefined.</p>



<a name="178803255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803255">(Oct 22 2019 at 22:03)</a>:</h4>
<p>So if that's not true, and we can get documentation into LLVM guaranteeing the behavior of unwinding over C frames not compiled with <code>-fexceptions</code>, then I think Rust could officially change this from "undefined behavior" to "implementation defined behavior," and the <code>no_unwind</code> optimization would just need to be made available to users somehow.</p>



<a name="178803351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803351">(Oct 22 2019 at 22:04)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> The main point is that we should provide a safe default that allows unwinding. If you want dead code elimination then you can explicitly mark certain C APIs that do not unwind. If you look at the libc headers you will see that certain functions are marked <code>noexcept</code> when compiled with a C++ compiler, rather than the other way around.</p>



<a name="178803373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803373">(Oct 22 2019 at 22:05)</a>:</h4>
<p>Can we create a hackmd and start to collect the key points here?</p>



<a name="178803404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803404">(Oct 22 2019 at 22:05)</a>:</h4>
<p>One thing I found very unclear, <span class="user-mention" data-user-id="143274">@Amanieu</span>, was what all the UB considerations were, especially with respect to longjmp</p>



<a name="178803434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803434">(Oct 22 2019 at 22:05)</a>:</h4>
<p>hackmd doc I just created: <a href="https://hackmd.io/ymsEL6OpR6OSMoFr1As1rw" target="_blank" title="https://hackmd.io/ymsEL6OpR6OSMoFr1As1rw">https://hackmd.io/ymsEL6OpR6OSMoFr1As1rw</a></p>



<a name="178803440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803440">(Oct 22 2019 at 22:05)</a>:</h4>
<p>unfortunately, I have to run now to make dinner :)</p>



<a name="178803522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803522">(Oct 22 2019 at 22:07)</a>:</h4>
<p>To be clear, I am definitely sympathetic to that argument, <span class="user-mention" data-user-id="143274">@Amanieu</span> -- and also to the point that it behooves us to be analogous with C and C++</p>



<a name="178803695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803695">(Oct 22 2019 at 22:09)</a>:</h4>
<blockquote>
<p>To be clear, I am definitely sympathetic to that argument, <span class="user-mention silent" data-user-id="143274">Amanieu</span> -- and also to the point that it behooves us to be analogous with C and C++</p>
</blockquote>
<p>Same here.</p>



<a name="178803793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178803793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178803793">(Oct 22 2019 at 22:10)</a>:</h4>
<p><code>longjmp</code> on Windows uses unwinding, but it is somewhat magic: it calls destructors but it is ignored by <code>noexcept</code>.</p>



<a name="178805077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178805077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178805077">(Oct 22 2019 at 22:31)</a>:</h4>
<blockquote>
<p>hackmd doc I just created: <a href="https://hackmd.io/ymsEL6OpR6OSMoFr1As1rw" target="_blank" title="https://hackmd.io/ymsEL6OpR6OSMoFr1As1rw">https://hackmd.io/ymsEL6OpR6OSMoFr1As1rw</a></p>
</blockquote>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> or <span class="user-mention" data-user-id="132920">@gnzlbg</span> -- one thing I think would be super helpful would be if you could enumerate in this document some of the key scenarios you are curious about. For example, I saw some talk about a longjmp that unwinds over a "noexcept" frame. It seems like you two had a few such scenarios in mind.</p>



<a name="178805367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178805367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178805367">(Oct 22 2019 at 22:36)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I believe <code>longjmp</code> w/ MSVC does _not_ call destructors; I think gnzlbg said that LLVM's difference in behavior here seems to be a Clang bug</p>



<a name="178835870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178835870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178835870">(Oct 23 2019 at 09:17)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> this is essentially the opposite proposal, e.g., instead of making C++ <code>noexcept(true)</code> the default for C APIs, it makes <code>noexcept(false)</code> the default, and adds some way to mark some APIs as <code>noexcept(true)</code></p>



<a name="178835877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178835877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178835877">(Oct 23 2019 at 09:17)</a>:</h4>
<p>(e.g. the <code>#[no_unwind]</code> attribute)</p>



<a name="178835989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178835989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178835989">(Oct 23 2019 at 09:18)</a>:</h4>
<p>That opens the design of a large language feature, e.g., should <code>#[no_unwind]</code> be part of the type system ? (C++ didn't do that at first in C++11 but had to fix that in C++17)</p>



<a name="178836135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178836135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178836135">(Oct 23 2019 at 09:20)</a>:</h4>
<p>If its part of the type system its technically an effect, and that opens the question of how does one write code that's generic over <code>noexcept</code> (C++ provides a way to query whether an expression is <code>noexcept</code>, <code>noexcept</code> overloading, allows using <code>noexcept</code> in const contexts for constraining impls similar to where clauses, etc.)</p>



<a name="178836179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178836179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178836179">(Oct 23 2019 at 09:21)</a>:</h4>
<p>it also has implications for libstd, e.g., how to make libstd "<code>#[no_unwind]</code> correct", etc.</p>



<a name="178836302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178836302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178836302">(Oct 23 2019 at 09:22)</a>:</h4>
<p>the application of such a feature goes way beyond C FFI as well, e.g., lots of code wants to make sure that certain operations cannot unwind, and <code>#[no_unwind]</code> would achieve that, so the use cases fan out a lot</p>



<a name="178837718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178837718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178837718">(Oct 23 2019 at 09:43)</a>:</h4>
<p>Usually, <code>#[no_unwind]</code> would also be able to make some currently incorrect uses of <code>AssertUnwindSafe</code> correct, e.g., by being able to express that some part of the code never unwinds, and therefore, cannot violate any panic safety invariants.</p>



<a name="178837834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178837834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178837834">(Oct 23 2019 at 09:44)</a>:</h4>
<p>And well then there is also the issue of allowing <code>#[no_unwind]</code> in trait methods, for example. I don't think I've ever written a <code>Drop</code> implementation where allowing <code>Drop::drop</code> to unwind would be something I want.</p>



<a name="178837876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178837876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178837876">(Oct 23 2019 at 09:45)</a>:</h4>
<p>e.g. for something as simple as dropping a <code>[T]</code>, if one <code>T::drop</code> panics, then <code>[T]::drop</code> tries to drop all other elements, and then it panics (and if a second <code>T::drop</code> panics, then the program aborts)</p>



<a name="178838000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178838000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178838000">(Oct 23 2019 at 09:47)</a>:</h4>
<p>That code could be much simpler if <code>T::drop</code> is known not to panic, and well, if you are building a <code>Vec&lt;T&gt;</code> on top of it, there is one element for which <code>T::drop</code> failed, but for which the <code>Vec&lt;T&gt;</code> deallocates its memory</p>



<a name="178838129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178838129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178838129">(Oct 23 2019 at 09:49)</a>:</h4>
<p>so there is a <code>T</code> in your program for which the destructor did not succeed and whose memory was deallocated</p>



<a name="178838918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178838918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178838918">(Oct 23 2019 at 09:59)</a>:</h4>
<p>Yes, allowing drops to panic was a mistake, but I think it's outside the scope of this WG. Let's stay on topic.</p>



<a name="178839001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178839001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178839001">(Oct 23 2019 at 10:00)</a>:</h4>
<p>While I mentioned a <code>#[no_unwind]</code> attribute, my proposal would just as well work with <code>extern "C nounwind"</code>. The key point is just allowing unwinding by default in <code>extern "C"</code>.</p>



<a name="178839846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/no%20C%20unwind%3F/near/178839846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/no.20C.20unwind.3F.html#178839846">(Oct 23 2019 at 10:13)</a>:</h4>
<p>I've branched that to the "noexcept-like feature" thread</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>